<template>
  <div>
    <h1>查看科室</h1>
    <hr />
    <div>
      <div class="block" style="width: 50%; margin-left: 200px">
        <span class="demonstration">选择医院</span>
        <el-cascader
          v-model="value"
          :options="options"
          :props="{ expandTrigger: 'hover' }"
          @change="handleChange"
        ></el-cascader>
       
        <el-button icon="el-icon-search" type="primary" @click="getBadDepart">已弃科室</el-button>
      </div>
    </div>
    <div>
      <div
        style="
          background-color: #e4f2ff;
          border: 1px solid #6ab7fe;
          margin: 0px auto;
          height: 40px;
          line-height: 40px;
          width: 65%;
        "
      >
        <i
          class="el-icon-message-solid"
          style="color: #6ab7fe; line-height: 40px"
        >
        </i>
        <label style="font-size: 14px">
          科室总数：{{ departByHid.total }}
        </label>
      </div>
    </div>

    <div>
      <!-- 表格 -->
      <el-table
        ref="multipleTable"
        :data="departByHid.list"
        tooltip-effect="dark"
        style="width: 65%; margin: 0px auto"
        @selection-change="handleSelectionChange"
      >
        <el-table-column
          type="index"
          label="序号"
          width="120"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="dname"
          label="科室名"
          width="120"
        ></el-table-column>
        <el-table-column
          prop="tbSection.sname"
          label="科室负责人"
          width="120"
        ></el-table-column>
        <el-table-column prop="softdel" label="科室状态" width="120">
          <template slot-scope="scope">
            <label v-if="scope.row.softdel == 1">正常</label>
            <label v-if="scope.row.softdel == 0">已弃用</label>
          </template>
        </el-table-column>
        <el-table-column
          prop="tbSection.gender"
          label="负责人性别"
          width="120"
        ></el-table-column>
        <el-table-column label="操作" width="180" align="center">
          <template slot-scope="scope">
            <el-button size="mini" type="success" @click="bedDetails(scope.row)"
              >详情</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 分页 -->
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="departByHid.pageNum"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="departByHid.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="departByHid.total"
    >
    </el-pagination>
  </div>
</template>

<script>
import {
  getAllHospital,
  getDepartmentByHid,
} from "@/api/department.js";
export default {
  data() {
    return {
      departByHid: [],
      value: [],
      options: [],
      pageInfo: {
        pageNum: 1,
        pageSize: 5,
      },
    };
  },
  mounted() {
    this.getAllHospitals();
    this.handleChange([1])
  },
  methods: {
    // getBadDepart(){//弃用科室查找
      //将hid传过去

    // },
    handleSizeChange(val) {
      this.pageInfo.pageSize = val;
      this.pageInfo.pageNum = 1;
      this.handleChange(this.value)
    },
    handleCurrentChange(val) {
      this.pageInfo.pageNum = val;
      this.handleChange(this.value)
    },
    handleChange(value) {
      // alert(value)
      //选择医院后,获取所有的科室信息和可是负责人
      getDepartmentByHid({
        hid: value,
        pageNum: this.pageInfo.pageNum,
        pageSize: this.pageInfo.pageSize,
      }).then((res) => {
        if (res.data.code == 200) {
          this.departByHid = res.data.data;
        }
      });
    },
    getAllHospitals() {
      getAllHospital().then((res) => {
        if (res.data.code == 200) {
          this.allHospital = res.data.data;
          for (var i = 0; i < this.allHospital.length; i++) {
            this.options.push({
              value: this.allHospital[i].id,
              label: this.allHospital[i].hname,
            });
          }
        }
      });
    },
    bedDetails(row) {
      this.$router.push({
        path: "/Home/bedDetailByDid",
        query: { did: row.did, dname: row.dname },
      });
    },
  },
};
</script>

<style>
</style>